<%@page import="com.amado.easyui2.constant.GlobalConstants"%>
<%@page import="com.amado.easyui2.domain.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="common.jsp" %>    
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户管理</title>
    <link rel="stylesheet" type="text/css" href="<%=contextPath %>/css/index.css">
    <link rel="stylesheet" type="text/css" href="<%=contextPath %>/css/report.css">
    <link rel="stylesheet" type="text/css" href="<%=contextPath %>/jquery-easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="<%=contextPath %>/jquery-easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="<%=contextPath %>/jquery-easyui/themes/wu.css">
    <script type="text/javascript" src="<%=contextPath %>/jquery-easyui/jquery.min.js"></script>
    <script type="text/javascript" src="<%=contextPath %>/jquery-easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="<%=contextPath %>/jquery-easyui/jquery.easyui.extend.js"></script>
    <script type="text/javascript" src="<%=contextPath %>/js/DateUtil.js"></script>
    <script type="text/javascript" src="<%=contextPath %>/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body class="easyui-layout">

<div data-options="region:'north'" style="height:113px;">
    <div class="title">
		<div class="title-common-layer">
            <div class="title-info-box" >
            	<%
            		User user = (User)session.getAttribute(GlobalConstants.SESSION_USER_ALL);
            	%>
                <span style="font-size: 20px;font-weight: 700">部门：<%=user!=null?user.getDepartmentName():"" %></span>
                <span style="font-size: 20px;font-weight: 700">用户：<%=user!=null?user.getUserName():"" %></span>
            </div>
        </div>
        <div class="title-common-layer">
            <div class="title-time-box">
					<span>
						<input id="styleBox" class="easyui-combobox">
					</span>
                <span></span>
            </div>

            <div class="title-btn-box">
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-help'" style="margin-top: 1px; width: 60px;">帮助</a>
                <a href="javascript:void(0)" id="updatepassword" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" style="margin-top: 1px; width: 80px;">修改密码</a>
                <a href="javascript:void(0)" id="cancel" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" style="margin-top: 1px; width: 60px;">注销</a>
            </div>
        </div>
    </div>
</div>
<!-- 245 252 -->
<!-- 155 342 -->
<div title="功能菜单" data-options="region:'west',split:true" style="width:155px;">
    <div class="easyui-accordion" data-options="border:false,fit:true,selected:-1">
        <div title="基础信息管理" data-options="iconCls:'icon-base'">
            <ul class="menu-box">
                <li>
                    <div>
                        <a href="javascript:void(0)" name="html/department/departmentList.html">
                            <span>部门管理</span>
                        </a>
                    </div>
                </li>
                <!-- <li>
                    <div>
                        <a href="javascript:void(0)" name="html/drivingSchool/drivingschoolList.html">
                            <span>驾校管理</span>
                        </a>
                    </div>
                </li> -->
                <li>
                    <div>
                        <a href="javascript:void(0)" name="html/user/userList.html">
                            <span>用户管理</span>
                        </a>
                    </div>
                </li>
                <li>
                    <div>
                        <a href="javascript:void(0)" name="html/student/studentList.html">
                            <span>学员管理</span>
                        </a>
                    </div>
                </li>
                 <li>
                    <div>
                        <a href="javascript:void(0)" name="html/coach/coachList.html">
                            <span>教练车管理</span>
                        </a>
                    </div>
                </li>
                 <li>
                    <div>
                        <a href="javascript:void(0)" name="html/coachStaff/coachStaffCarList.html">
                            <span>教练员管理</span>
                        </a>
                    </div>
                </li> 
                
                
               
            </ul>
        </div>
        <!-- 
        <div title="不良行为管理" data-options="iconCls:'icon-behavior'">
            <ul class="menu-box">
                <li>
                    <div>
                        <a href="javascript:void(0)"  name="Behavior/BehaviorInfoList.html">
                            <span>泥头车不良行为管理</span>
                        </a>
                    </div>
                </li>
            </ul>
        </div>
         -->
    </div>
</div>
<div data-options="region:'center'" style="width:100%;">
    <div id="index-tab" class="easyui-tabs" data-options="border:false,fit:true">
        <div title="首页" style="background-color: #FFFFFF">
            	<div style="font-size: 50px;margin: 140px auto;width: 700px">欢迎使用驾校管理系统</div>
        </div>
    </div>
</div>

<div id="index-menu" class="easyui-menu" data-options="onShow:menuOnShowHandler" style="width:160px;">
    <div id="index-menu-closeSelf">关闭标签页</div>
    <div id="index-menu-closeOthers">关闭其他标签页</div>
    <div id="index-menu-closeLeft">关闭左侧标签页</div>
    <div id="index-menu-closeRight">关闭右侧标签页</div>
    <div id="index-menu-closeAll">关闭所有标签页</div>
</div>

<div id="common-dialog">
</div>
<div id="common-dialog-buttons" style="text-align: center;">
    <a href="javascript:void(0)" id="common-dialog-save" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>
    <a href="javascript:void(0)" id="common-dialog-reset" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">重置</a>
    <a href="javascript:void(0)" id="common-dialog-close" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">关闭</a>
</div>
</body>
<script type="text/javascript">
	$.fn.serializeObject = function()
	{
	    var o = {};
	    var a = this.serializeArray();
	    $.each(a, function() {
	        if (o[this.name] !== undefined) {
	            if (!o[this.name].push) {
	                o[this.name] = [o[this.name]];
	            }
	            o[this.name].push(this.value || '');
	        } else {
	            o[this.name] = this.value || '';
	        }
	    });
	    return o;
	};
	$.fn.serializeString = function()
	{
	    var o = {};
	    var a = this.serializeArray();
	    $.each(a, function() {
	        if (o[this.name] !== undefined) {
	            if (!o[this.name].push) {
	                o[this.name] = [o[this.name]];
	            }
	            o[this.name].push(this.value || '');
	        } else {
	            o[this.name] = this.value || '';
	        }
	    });
	    return JSON.stringify(o);
	};
    $(function(){
        $("#cancel").click(function () {
           // alert(1);
            window.location.href="userLoginServlet.do?method=loginOut";
        });
//         $("#updatepassword").click(function(){
//             var selTr = $("#dept-grid").datagrid("getSelections");

        
//                 openDialog({
//                     title:"用户信息编辑",
//                     width:800,
//                     height:360,
//                     maximizable:false,
//                     queryParams: { id: selTr[0].id},//设置了一个属性queryParams
//                     href:"html/user/userEdit.html"
//                 });
//             }
//         });
          $("#updatepassword").click(function () {
           // alert(1);

           openDialog({
               title:"修改密码",
               width:500,
               height:220,
               maximizable:false,
               href:"html/user/updatepassword.html"
           });

          });
       
        //时间显示
        window.setInterval(function(){
            var date = new Date();
            var second = date.getSeconds();

            date.setSeconds(second, 1000);

            $(".title-time-box span:last").html(date.toLocaleString());
        }, 1000);

        $("#styleBox").combobox({
            url:CONST.contextPath+"/json/style.json",
            method:"get",
            groupField:"group",
            textField:"text",
            valueField:"value",
            onSelect:function(record){
                var href = record.value;
                $.each($("link"),function(index,obj){
                    if(obj.href.toLowerCase()
                                    .indexOf("easyui.css") > -1){
                        obj.href = href;
                        return false;
                    }
                });
            }
        });

        //左侧菜单点击事件
        $(".menu-box li div a").click(function(){
            var title = $.trim($(this).text());
            var href = $(this).attr("name");

            if($(".menu-box div.selected")){
                $(".menu-box div.selected").removeClass("selected");
            }

            $(this).parent().addClass("selected");

            openMenu({
                title:title,
                href:href,
                target:{
                    mode:"tab",
                    tabId:"#index-tab"
                }
            });

        }).hover(function(){
            $(this).parent().addClass("hover");
        },function(){
            $(this).parent().removeClass("hover");
        });

        //弹出框初始化
        $("#common-dialog").dialog({
            cache:false,
            modal:true,
            closed:true,
            resizable:true,
            buttons:"#common-dialog-buttons",
            onClose:function(){
                $("#common-dialog-buttons").children(":hidden").show();
                $(this).panel().find(".panel-body").children().remove();

                if(null != intervalId){
                    window.clearInterval(intervalId);
                    intervalId = null;
                }

                if(null != timeoutId){
                    window.clearTimeout(timeoutId);
                    timeoutId = null;
                }
            }
        });
        //弹出框按钮事件
        $("#common-dialog-save").click(function(){
        	debugger;
            var ifValid = $("#common-dialog form")
                    .form("enableValidation")
                    .form("validate");
            if(ifValid){                
                $.post($("#common-dialog form").attr("action"),{data:$("#common-dialog form").serializeString()},function(data){
                	 //是否有返回值
                	 if(data){
                		data = jQuery.parseJSON(data);
                		//是否成功标识
	                	if(data.resultCode=="1"){
	                		 Messager.show({
		                         title:"&nbsp;",
		                         content:"操作成功"
		                     });
		                	 $("#common-dialog").dialog("close");
	                	}else{
	                		//失败，打印失败信息
	                		Messager.show({
		                         title:"&nbsp;",
		                         content:data.resultMessage,
		                         icon:'error'
		                     });
	                	}
                	 }else{
                		 Messager.show({
	                         title:"&nbsp;",
	                         content:"操作成功"
	                     });
	                	 $("#common-dialog").dialog("close");
                	 }
				}, "text");
            }
//             $('#refreshbtn').click(function() {
//                 $.datagrid("reload",serializeForm($('#coache2-grid-toolbar')));
//             });
        });
        
       
        
        $("#common-dialog-reset").click(function(){
            $("#common-dialog form").form("clear");
        });

        $("#common-dialog-close").click(function(){
            $("#common-dialog").dialog("close");
        });

        //tab页标题事件委派
        $("#index-tab").on("contextmenu","li:gt(0)",function(event){
            event.preventDefault();

            var thisTabTitle = $(this).text();
            $("#index-tab").tabs("select", thisTabTitle);

            $("#index-menu").menu("show",{
                left:event.pageX,
                top:event.pageY
            });
        });

        //菜单相关按钮事件
        $("#index-menu-closeSelf").click(function(){
            var curTab = $("#index-tab").tabs("getSelected");

            var curTabTitle = curTab.panel("options").title;

            $("#index-tab").tabs("close",curTabTitle);
        });

        $("#index-menu-closeOthers").click(function(){
            var curTab = $("#index-tab").tabs("getSelected");

            var curTabTitle = curTab.panel("options").title;

            $.each($("#index-tab li"),function(index, obj){

                var tabTitle = $(obj).text();

                if(index > 0 && tabTitle != curTabTitle){
                    $("#index-tab").tabs("close", tabTitle);
                }
            });

            $("#index-tab").tabs("select",curTabTitle);
        });

        $("#index-menu-closeLeft").click(function(){
            var curTab = $("#index-tab").tabs("getSelected");

            var curTabIndex = $("#index-tab").tabs("getTabIndex", curTab);
            var curTabTitle = curTab.panel("options").title;

            $.each($("#index-tab li:lt(" + curTabIndex + ")"), function(index, obj){
                if(index > 0){
                    var tabTitle = $(obj).text();

                    $("#index-tab").tabs("close", tabTitle);
                }
            });

            $("#index-tab").tabs("select",curTabTitle);
        });

        $("#index-menu-closeRight").click(function(){
            var curTab = $("#index-tab").tabs("getSelected");

            var curTabIndex = $("#index-tab").tabs("getTabIndex", curTab);
            var curTabTitle = curTab.panel("options").title;

            $.each($("#index-tab li:gt(" + curTabIndex + ")"), function(index, obj){
                var tabTitle = $(obj).text();

                $("#index-tab").tabs("close", tabTitle);
            });

            $("#index-tab").tabs("select",curTabTitle);
        });

        $("#index-menu-closeAll").click(function(){
            var curTab = $("#index-tab").tabs("getSelected");

            var curTabIndex = $("#index-tab").tabs("getTabIndex", curTab);
            var curTabTitle = curTab.panel("options").title;

            $.each($("#index-tab li"), function(index, obj){
                if(index > 0){
                    var tabTitle = $(obj).text();

                    $("#index-tab").tabs("close", tabTitle);
                }
            });
        });
//         $("#updatePassWord").click(function () {
//        	 window.location.href="html/student/studentUpdatePassword.html";
// 		});
        

    });

    //记录运行函数ID
    var intervalId = null;
    var timeoutId = null;

    //新增tab页
    function openMenu(menuConfig){

        var title = menuConfig.title;
        var href = menuConfig.href;

        var mode = menuConfig.target.mode;

        if("tab" == mode){

            var tabId = menuConfig.target.tabId;

            if($(tabId).tabs("exists",title)){
                $(tabId).tabs("select",title)
            }else{
                $(tabId).tabs("add",{
                    title:title,
                    href:href,
                    tools:[{
                        iconCls:"icon-mini-refresh",
                        handler:function(){
                            var curTab = $(tabId).tabs("getSelected");
                            curTab.panel("refresh");
                        }
                    }],
                    closable:true
                });
            }

        }else if("dialog" == mode){
            openDialog({
                type:"view",
                title:"&nbsp;",
                width:800,
                height:400,
                href:href
            });
        }else if("blank" == mode){
            window.open(href);
        }
    }

    //新增dialog
    function openDialog(config){
        if("view" == config.type){
            $("#common-dialog-buttons").children(":not(a[id='common-dialog-close'])").hide();
        }

        $("#common-dialog").dialog(config).window('center').dialog("open");
    }

    //提示信息
    var Messager = {
        "alert":function(config){
            $.messager.alert(config.title, config.content, config.type);
        },
        "show":function(config){
            $.messager.show({
                title:config.title,
                msg:config.content,
                showType:"fade",
                timeout:1000,
                style:{
                    right:"",
                    bottom:""
                }
            });
        }
    }

    //菜单显示后处理方法
    function menuOnShowHandler(item){
        var selTab = $("#index-tab").tabs("getSelected");

        var selTabIndex = $("#index-tab").tabs("getTabIndex", selTab);

        var leftExist = $("#index-tab li:lt(" + selTabIndex + ")").length - 1 > 0;
        var rightExist = $("#index-tab li:gt(" + selTabIndex + ")").length > 0;
        var othersExist = leftExist || rightExist;

        leftExist
                ? $("#index-menu").menu("enableItem",$("#index-menu-closeLeft"))
                : $("#index-menu").menu("disableItem",$("#index-menu-closeLeft"));

        rightExist
                ? $("#index-menu").menu("enableItem",$("#index-menu-closeRight"))
                : $("#index-menu").menu("disableItem",$("#index-menu-closeRight"));


        othersExist
                ? $("#index-menu").menu("enableItem",$("#index-menu-closeOthers"))
                : $("#index-menu").menu("disableItem",$("#index-menu-closeOthers"));
    }
</script>
</html>